package com.guiguli.RuntimeDemo1;

import java.io.IOException;

public class RuntimeDemo1 {
    public static void main(String[] args) {
        //3.获取Runtime对象
        Runtime r1 = Runtime.getRuntime();
        Runtime r2 = Runtime.getRuntime();
        System.out.println(r1==r2);     //true表示这两个是同一个对象 Runtime只能创建一个

        //2.停止虚拟机
        //Runtime.getRuntime().exit(0);

        //3.获取CPU的线程数
        System.out.println(Runtime.getRuntime().availableProcessors());//16

        //4.总内存大小 单位是byte
        System.out.println(Runtime.getRuntime().maxMemory()/1024/1024+"MB");

        //5.已经获取的总内存大小,单位是byte
        System.out.println(Runtime.getRuntime().totalMemory()/1024/1024+"MB");

        //6.剩余内存大小
        System.out.println(Runtime.getRuntime().freeMemory()/1024/1024+"MB");

        //7.运行cmd命令
        try {
            Runtime.getRuntime().exec("notepad");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
